package cs342.uwosh.edu.QuizApp.database;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class Connect {
	URL url;
	HttpURLConnection connection;
	boolean isValid;
	
	public Connect(){
		url = null;
	    connection = null;
	    isValid = false;
	}
	
	public boolean authentication(String authURL){
	    try{
	        url = new URL(authURL);
	        connection = (HttpURLConnection)url.openConnection();
	        BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
	        String line;
	        StringBuffer response = new StringBuffer(); 
	        while((line = in.readLine()) != null) {
	            response.append(line);
	        }
	        in.close();
	        int value = Integer.parseInt(response.toString());
	        if(value == 1){
	       	 isValid = true;
	        }
	        else{
	        	isValid = false;
	        }
	    }
	    catch(Exception e){   
	          e.printStackTrace();
	    } 
	    finally{   
	        if(connection != null) 
	            connection.disconnect();
	    }
		return isValid;
	}//end of authentication
	
	public void upload(){
		
	}

}//end of class